
package com.ukao.pad.presenter;

import android.content.Context;

import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.BaseBean;
import com.ukao.pad.bean.BatchlTabBean;
import com.ukao.pad.bean.PrintAloneBean;
import com.ukao.pad.bean.StringBean;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.Utils;
import com.ukao.pad.view.FactoryTabView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class FactoryTabPesenter extends BasePresenter<FactoryTabView> {



    public FactoryTabPesenter(FactoryTabView view) {
        attachView(view);
    }




    /*离厂 右边*/
    public void BatchOutlist( String  status ,String  code,int pageNum,int  pageSize) {


        HashMap     mHashMap=new HashMap<String,String>();
        if (!status.isEmpty()){
            mHashMap.put("status",status) ;
        }
        mHashMap.put("code",code) ;
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.BatchOutlist(Constant.createParameter(mHashMap)),
                new ApiCallback<BatchlTabBean>() {
                    @Override
                    public void onSuccess(BatchlTabBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadSuccess(model.getData().getList(), model.getData().getPages());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }
                    @Override
                    public void onNoNewWork() {
                        mvpView.showNoNetwork();
                    }

                    @Override
                    public void onFinish() {

                        mvpView.refreshFinish();

                    }
                });
    }




    public void batchIndelete(Context mContext, String id) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.batchOutdelete(Constant.createParameter(mHashMap)),
                new ApiCallback<BaseBean>() {
                    @Override
                    public void onSuccess(BaseBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.deleteSuccess("删除成功");

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /*確定出厂　参数*/
    public void finishFactory(String  id ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.leaveComplete(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadFinishSuccess();
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }

    /*打印衣物清单　参数*/
    public void printbatchOut(String  id ) {
        mvpView.showLoading();
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.printbatchOut(Constant.createParameter(mHashMap)),
                new ApiCallback<PrintAloneBean>() {
                    @Override
                    public void onSuccess(PrintAloneBean model) {

                        if (model.getHttpCode() == 200) {
                           mvpView.loadPrintbatchOutSuccess(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }



}
